#include <boost/mem_fn.hpp>
#include <algorithm>

#include "Mesh.h"
#include "Material.h"

using namespace slak::mesh;

void Patch::render()
{
	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_FLOAT, 0, vertices);

	if (normals) {
		glEnableClientState(GL_NORMAL_ARRAY);
		glNormalPointer(GL_FLOAT, 0, normals);
	}
	
	if (indices)
		glDrawElements(draw_mode, elem_count, GL_UNSIGNED_INT, indices);
	else
		glDrawArrays(draw_mode, 0, vertex_count);
	
	glDisableClientState(GL_VERTEX_ARRAY);
}


void Mesh::render() 
{
	for(MaterialList::iterator it = materials.begin();
	    it != materials.end(); it++) 
		(*it)->render(mat2patches[*it]); 
}


